package cn.fintecher.pangolin.service.business.model.request;

import cn.fintecher.pangolin.common.enums.AssistStatus;
import cn.fintecher.pangolin.entity.mysql.QAssistCase;
import com.querydsl.core.BooleanBuilder;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;

import java.util.List;
import java.util.Objects;

/**
 * @Author : wangxiangdong
 * @Description : 案件协催案件请求model
 * @Date : 2018/7/16.
 */
@Data
public class AssistCaseSearchRequest{

    @ApiModelProperty("外访案件Id")
    private List<String> assistCaseIds;

    @ApiModelProperty("姓名")
    private String personalName;

    @ApiModelProperty("委托方Id")
    private String principalId;

    @ApiModelProperty("委托方名称")
    private String principalName;

    @ApiModelProperty("证件号")
    private String certificateNo;

    @ApiModelProperty(notes = "案件编号")
    private String caseNumber;

    @ApiModelProperty("批次号")
    private String batchNumber;

    @ApiModelProperty(notes = "协助状态")
    private AssistStatus assistStatus;

    @ApiModelProperty(notes = "页数")
    private Integer page;

    @ApiModelProperty(notes = "每页大小")
    private Integer size;

    @ApiModelProperty(notes = "当前外放协助催收员")
    private String assistCollector;

    @ApiModelProperty(notes = "地址")
    private String addressDetail;

    public BooleanBuilder generateQueryBuilder() {
        BooleanBuilder booleanBuilder = new BooleanBuilder();
//        if (Objects.nonNull(this.assistCaseIds)) {
//            booleanBuilder.and(QAssistCase.assistCase.caseId.eq(this.assistCaseIds));
//        }
        if(Objects.nonNull(this.principalId)){
            booleanBuilder.and(QAssistCase.assistCase.principalId.eq(this.principalId));
        }
        if (Objects.nonNull(this.assistStatus)) {
            booleanBuilder.and(QAssistCase.assistCase.assistStatus.eq(this.assistStatus));
        }
        if (Objects.nonNull(this.batchNumber)) {
            booleanBuilder.and(QAssistCase.assistCase.batchNumber.eq(this.batchNumber));
        }
        if (Objects.nonNull(this.caseNumber)) {
            booleanBuilder.and(QAssistCase.assistCase.caseNumber.eq(this.caseNumber));
        }
        if (Objects.nonNull(this.certificateNo)) {
            booleanBuilder.and(QAssistCase.assistCase.certificateNo.eq(this.certificateNo));
        }
        if (Objects.nonNull(this.personalName)) {
            booleanBuilder.and(QAssistCase.assistCase.personalName.eq(this.personalName));
        }
        if(Objects.nonNull(this.assistCollector)){
            booleanBuilder.and(QAssistCase.assistCase.assistCollector.realName.like(StringUtils.join("%",this.assistCollector,"%")));
        }
        if (Objects.nonNull(this.addressDetail)) {
            booleanBuilder.and(QAssistCase.assistCase.addressDetail.like(StringUtils.join("%",this.addressDetail,"%")));
        }
        return booleanBuilder;
    }

}
